package HomeWork4;

public class Ticket {
    private int ticketNum;

    public int getTicketNum() {
        return ticketNum;
    }

    public void setTicketNum(int ticketNum) {
        this.ticketNum = ticketNum;
    }

    public Ticket(int ticketNum) {
        this.ticketNum = ticketNum;
    }
    public synchronized int sellTicket(int num) throws Exception {
        if (ticketNum>=num){
            ticketNum-=num;
            if(ticketNum==0){
                System.out.println("最后一张票卖出去了");
            }
        }else{
            System.out.println("没票了");
            ticketNum=0;

                }

        return ticketNum;
    }

    }

